package main

import (
	"log"

	"github.com/gin-gonic/gin"
	"zhonghui/console/api"
	"zhonghui/console/models"
	"zhonghui/console/warehouse/dbx"
	"zhonghui/console/warehouse/dbx/db_zh_kernel"
	"zhonghui/console/warehouse/envx"
	"zhonghui/console/worker"
)

func main() {
	dbx.SetRedisPrefix("zh-console")

	// 非dev环境下，关闭控制台颜色并开启Release模式
	if !envx.InDev() {
		gin.DisableConsoleColor()
		gin.SetMode(gin.ReleaseMode)
	}

	db, _ := db_zh_kernel.Client().DB()
	store := models.NewStore(db)

	// 增加后台任务
	if envx.InTest() || envx.InProd() {
		// go new(worker.MpAccessTokenWorker).Start()
		// go new(worker.SuiteAccessTokenWorker).Start()
		// go worker.NewAppAccessTokenWorker(store).Start()
		// go worker.NewProviderAccessTokenWorker(store).Start()

		// go new(worker.TaskCompleteWorker).Start()
		// go new(worker.UserPropWorker).Start()
		go new(worker.ChartsDownloadWorker).Start()

		// go new(worker.TaskScanWorker).Start(5, 0)
		// go new(worker.TaskScanWorker).Start(5, 1)
		// go new(worker.TaskScanWorker).Start(5, 2)
		// go new(worker.TaskScanWorker).Start(5, 3)
		// go new(worker.TaskScanWorker).Start(5, 4)
		//
		// go new(worker.TaskScanWorkerJD).Start(3, 0)
		// go new(worker.TaskScanWorkerJD).Start(3, 1)
		// go new(worker.TaskScanWorkerJD).Start(3, 2)

		// mqSms := new(consumer.SmsSendConsumer)
		// go mqx.StartNsqConsumer(mqSms, mqSms.GetTopicName(), mqSms.GetQueueName(), 5)
		//
		// mqFile := new(consumer.FileParseConsumer)
		// go mqx.StartNsqConsumer(mqFile, mqFile.GetTopicName(), mqFile.GetQueueName(), 1)
	}

	if envx.InDev() {
		// mqFile := new(consumer.FileParseConsumer)
		// go mqx.StartNsqConsumer(mqFile, mqFile.GetTopicName(), mqFile.GetQueueName(), 1)
		// service.TriggerFileParseTask(16)

		// service.TriggerSmsSendTask(3, 32)
		//
		// mqSms := new(consumer.SmsSendConsumer)
		// go mqx.StartNsqConsumer(mqSms, mqSms.GetTopicName(), mqSms.GetQueueName(), 20)

		// go new(worker.TaskScanWorker).Start()
		// go new(worker.TaskCompleteWorker).Start()
		// go new(worker.UserPropWorker).Start()
	}

	if envx.InProd() {
		// go new(worker.P).Start()
	}

	server := api.NewServer(store, db_zh_kernel.Client())

	//  docker环境下固定端口号
	port := ":3090"
	// 非docker环境下指定端口号
	if envx.InDev() {
		port = ":31304"
	}

	log.Fatal(server.Start(port))
}
